package cn.com.scitc.servlet.paid;

import cn.com.scitc.dao.PaidDao;
import cn.com.scitc.model.Paid;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;

@WebServlet(urlPatterns = "/paid/list")
public class PaidListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PaidDao paidDao = new PaidDao();
        List<Paid> list = paidDao.findAll();
        BigDecimal total = BigDecimal.valueOf(0);
        for (Paid paid : list) {
            total = total.add(paid.getAmountpaid());
        }
        System.out.println("total: " + total);
        req.setAttribute("total", total);
        req.setAttribute("list", list);

        req.getRequestDispatcher("/WEB-INF/paid/list.jsp").forward(req, resp);
    }
}
